<template>
	<view class="inwardAppointApprove">
		<uni-nav-bar
			color="#ffffff"
			background-color="#00aded"
			:statusBar="true"
			title="调拨通知单审核"
			fixed="true"
			left-icon="left"
			left-text="返回"
			@clickLeft="back"
		></uni-nav-bar>
		<view class="inwardAppointApprove_top">
			<!-- 搜索 -->
			<!-- 搜索 -->
			<dil-search :columnData="options.columnDataList" @onSearch="onSearch" v-if="options.columnDataList.length > 0"></dil-search>
		</view>
		<view class="inwardAppointApprove_main">
			<dil-card class="dilCard" @emitEvent="emitEvent" v-bind.sync="options"></dil-card>
		</view>
		<view class="inwardAppointApprove_floot"></view>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
export default {
	data() {
		return {
			options: {
				requestUrl: '/api/v1/ams/getproductionRequirementworkflowList?apiId=625',
				requestQuery: {},
				cardSlotList: [
					{
						label: '同意',
						value: 'approveAgree',
						icon: 'bars',
						emitEvent: 'approveAgree',
						showCondition: "['待审批'].includes(item.approvalStatus) && ['已申报'].includes(item.status)"
					},
					{
						label: '驳回',
						icon: 'bars',
						emitEvent: 'approveRefuse',
						showCondition: "['待审批'].includes(item.approvalStatus) && ['已申报'].includes(item.status)"
					}
				],
				columnDataList: [],
				totalNum: 0
			}
		};
	},
	onShow() {
		uni.$emit('onShow', 1);
	},
	mounted() {},
	methods: {
		getOrderSection(item) {
			console.log("item",item);
			this.options.requestQuery = JSON.parse(JSON.stringify(Object.assign(this.options.requestQuery,item)));
		},
		back() {
			uni.switchTab({
				url: '/pages/index/index'
			});
		},
		onSearch(item) {
			this.options.requestQuery = JSON.parse(JSON.stringify(item));
		},
		emitEvent(eventName, cardItem) {
			this[eventName](cardItem);
		},
		approveAgree(item) {
			uni.showModal({
				cancelText: '取消',
				confirmText: '确定',
				title: '提示',
				content: '是否同意该需求申请',
				success: (res) => {
					if (res.confirm) {
						this.approveAgreeInwardAppointItem(item);
					} else {
						uni.showToast({
							title: '用户取消操作',
							type: 'info',
							duration: 2000
						});
					}
				}
			});
		},
		async approveAgreeInwardAppointItem(item) {
			let data = {
				approve: 'agree',
				...item
			};
			const res = await this.$myRequest({
				url: '/api/v1/ams/productionRequirementChange',
				data: data
			});
			if (res.data.status == 'succeed') {
				uni.showToast({
					title: res.data.message,
					icon: 'success',
					duration: 2000
				});
				setTimeout(() => {
					this.getOrderSection();
				}, 2200);
			} else {
				uni.showToast({
					title: res.data.message,
					icon: 'error',
					duration: 2000
				});
			}
		},
		approveRefuse(item) {
			uni.showModal({
				cancelText: '取消',
				confirmText: '确定',
				title: '提示',
				content: '是否驳回该需求申请',
				success: (res) => {
					if (res.confirm) {
						this.approveRefuseInwardAppointItem(item);
					} else {
						uni.showToast({
							title: '用户取消操作',
							type: 'info',
							duration: 2000
						});
					}
				}
			});
		},
		async approveRefuseInwardAppointItem(item) {
			let data = {
				approve: 'refuse',
				...item
			};
			const res = await this.$myRequest({
				url: '/api/v1/ams/productionRequirementChange',
				data: data
			}).catch((err) => {
				uni.showToast({
					duration: 2000,
					title: err,
					icon: 'error'
				});
			});
			if (res.data.status == 'succeed') {
				uni.showToast({
					title: res.data.message,
					icon: 'success',
					duration: 2000
				});
				setTimeout(() => {
					this.getOrderSection();
				}, 2200);
			} else {
				uni.showToast({
					title: res.data.message,
					icon: 'error',
					duration: 2000
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.inwardAppointApprove {
	width: 100vw;
	height: 100%;
	background-color: #f5f5f5;
	&_top {
		background-color: #fff;
	}
	&_main {
	}
	&_floot {
		background-color: #fff;
	}
}
</style>
